#ifndef BITFIELD_H_INCLUDED
#define BITFIELD_H_INCLUDED

/// fast Bitfield operations
namespace cvMath
{
	typedef unsigned long bitfield_t;

	/// Returns true when all mask bits are set in var.
	inline bool allFlags_on(bitfield_t var, const bitfield_t mask)
	{
		return (var & mask) == mask;
	}
	/// Returns true only when none of mask bits are set in var
	inline bool allFlags_off(bitfield_t var, const bitfield_t mask)
	{
		return (var & mask) == 0;
	}
	/// Returns true any of the mask bit is set in var
	inline bool someFlags_on(bitfield_t var, const bitfield_t mask)
	{
		return (var & mask);
	}
	/// Returns true only if some mask bits are set in var, but not all.
	inline bool someFlags_off(bitfield_t var, const bitfield_t mask)
	{
		return (var & mask) < mask;
	}
	/// Sets mask bits on
	inline void setFlag_on(bitfield_t &var, const bitfield_t mask)
	{
		var |= mask;
	}
	/// Sets mask bits off
	inline void setFlag_off(bitfield_t &var, const bitfield_t mask)
	{
		var &= (~mask);
	}

	/// Returns var limited with mask
	inline bitfield_t filterFlags(const bitfield_t var, const bitfield_t mask)
	{
		return (var & mask);
	}
};

#endif // BITFIELD_H_INCLUDED
